package com.tool.payment.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tool.payment.service.PaymentProxyService;

@Controller
@RequestMapping(value = "/notify/{product}/{mode}")
public class NotifyController {
	
	@Autowired
	private PaymentProxyService proxyService;

	@RequestMapping(value="")
	public String notify(@PathVariable("product") String product, @PathVariable("mode") String mode,HttpServletRequest request, HttpServletResponse response){
		
		String msg =  proxyService.payNotify(product, mode, request);
		if(StringUtils.isNotEmpty(msg)){
			try {
				response.setContentType("text/plain");  
				response.setCharacterEncoding("utf-8");
				response.getWriter().println(msg);
				response.flushBuffer();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return "";
	}

}
